/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.jm.financeiro.filter;

import java.util.Properties;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author joao
 */
public class EnviarEmail {

    private String mailSMTPServer = "smtp.mail.yahoo.com";
    private String mailSMTPServerPort = "465";
    private final static Logger logger = Logger.getLogger(SendMail.class.getName());

    public EnviarEmail() {
        super();
    }
    

    public static void enviaEmail() {
        Properties props = new Properties();
        /**
         * Parâmetros de conexão com servidor Yahoo
         */
        props.put("mail.smtp.host", "smtp.mail.yahoo.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "25");

        Session session = Session.getDefaultInstance(props,
                new javax.mail.Authenticator() {
                    @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("triunfosp@yahoo.com.br", "Emailsdos@p237");
                    }
                });

        /**
         * Ativa Debug para sessão
         */
        session.setDebug(true);

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("triunfosp@yahoo.com.br")); //Remetente

            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("jomello_br@hotmail.com")); //Destinatário(s)
            message.setSubject("Enviando email com JavaMail");//Assunto
            message.setText("Enviei este email utilizando JavaMail com minha conta Yahoo!");
            /**
             * Método para enviar a mensagem criada
             */
            Transport.send(message);

            System.out.println("Feito!!!");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}
